package pl.edu.pjwstk.kor.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import pl.edu.pjwstk.kor.sbql4j.project1.Project1Query;

import javax.servlet.ServletRequest;

@Controller
@RequestMapping("/p1")
public class Queries1 {
	private final Project1Query p1q;

	@Autowired
	public Queries1(Project1Query p1q) {
		this.p1q = p1q;
	}

	@RequestMapping("/main.html")
	public ModelAndView mainPage(ServletRequest request) {
		double cost = ServletRequestUtils.getDoubleParameter(request, "serviceCost", 5000.0);


		return new ModelAndView("/p1/main")
			.addObject("serviceCost", cost)
			.addObject("services1", p1q.query1(cost))
			.addObject("servicesNames", p1q.query2())
			.addObject("empNames", p1q.query3())
			.addObject("deals", p1q.query4())
			.addObject("discounts", p1q.query5())
			.addObject("rankCounts", p1q.query6())
		;
	}
	
}
